package com.human.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.human.entity.Contract;
import com.human.dao.ContractMapper;
import com.human.entity.ResultVo;
import com.human.service.IContractService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jzq
 * @since 2023-03-05
 */
@Service
public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> implements IContractService {

    @Resource
    ContractMapper contractMapper;

    @Override
    public ResultVo page(int current, int pageSize, String name) {
        //分页构造器
        Page pageInfo = new Page(current, pageSize);

        //执行查询
        IPage contractAndEmp = contractMapper.getContractAndEmp(pageInfo, name);
        return new ResultVo<Page>(true, "查询成功", contractAndEmp);
    }

    @Override
    public ResultVo getContracts() {
        List<Contract> contracts = contractMapper.selectList(null);
        return new ResultVo<Page>(true, "查询成功", contracts);
    }

    @Override
    public ResultVo getContractById(Integer id) {
        Contract contract = contractMapper.selectById(id);
        return new ResultVo<Page>(true, "查询成功", contract);
    }

    @Override
    public ResultVo deleteContractById(Integer id) {
        int i = contractMapper.deleteById(id);
        if (i > 0) {
            return new ResultVo<>(true, "删除成功");
        }
        return new ResultVo<>(true, "删除失败");
    }

    @Override
    public ResultVo addContract(Contract contract) {
        int i = contractMapper.insert(contract);
        if (i > 0) {
            return new ResultVo<>(true, "添加成功");
        }
        return new ResultVo<>(true, "添加失败");
    }

    @Override
    public ResultVo updateContract(Contract contract) {
        int i = contractMapper.updateContract(contract);
        if (i > 0) {
            return new ResultVo<>(true, "修改成功");
        }
        return new ResultVo<>(true, "修改失败");
    }


}
